<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@ include file="pub/top.jsp"%>

<!-- 全局变量 函数定义区 -->
<%!%>
<!-- 实例变量 函数定义区 -->
<%
	//网页title
	String JSPTITLE = "添加应用";
%>

<%@ include file="pub/head.jsp"%>
<!-- 样式添加区 -->
<style>
body {
	background-color: #fff
}
.mmar{
margin-left:25%
}
</style>
<link rel="stylesheet" href="<%=basePath%>assets/css/jquery-ui.custom.min.css" />
<!-- 下右内容区 -->
<div class="main-content-inner">
	<div class="breadcrumbs ace-save-state" id="breadcrumbs">
		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i>
			第三方应用管理
			</li>
			<li class="active"><%=JSPTITLE %></li>
		</ul>
	</div>
	<div class="page-content">
		<!-- page-header{ -->
		<div class="page-header">

			<div class="row">
				<div class="col-xs-12">
					<div class="clearfix">
						<div class="pull-right tableTools-container"></div>
						<div class="">
							<div class="btn-group" style="margin-top: 5px">
								<a href="#" class="btn-refresh btn  btn-xs "> <i
									class="im-spinner10 fa-spin"></i> 刷新
								</a>
							</div>
						</div>
					</div>
					<div id="demo" class="panel-collapse collapse ">
						<div class="panel-body well">
							<form>
								<div class="col-lg-12 col-sm-12">
									<button type="submit"
										class="btn btn-success btn-sm  pull-right">
										<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
										查找
									</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>

		</div>
		<!-- }page-header  -->

		<!-- table header2{ -->
		<div class="row">
			<div class="col-xs-9 tablehead2L"></div>
			<div class="col-xs-3 tablehead2R"></div>
		</div>
		<!-- }table -header2  -->
		<!--  table { -->

		<div class="row">
			<div class="col-xs-12">

				<form class="form-horizontal" action="" role="form" >
					<div class="form-group">
						<span class="mmar"><i style="color:red">*</i> app名称</span><br>
						<input type="text" id="aname" class="width-45 mmar" />
					</div>
					
					<div class="form-group" style="display:none">
						<span class="mmar"><i style="color:red">*</i> 联系人姓名</span><br>
						<input type="text" id="ualias" class="width-45 mmar onlynum" >
					</div>
					
					<div class="form-group">
						<span class="mmar"><i style="color:red">*</i> 联系人号码</span><br>
						<input type="text" id="uphone" class="width-45 mmar" />
					</div>
					
					<div class="form-group">
						<span class="mmar"><i style="color:red">*</i>机构logo</span><br>
						<input id="uploadFileInput1" type="file" style="display: none"
								size="45" name="uploadFileInput1" class="uploadFileInput" /> <img
								id="avatar1" class="editable img-responsive mmar"
								style="width:200px; height:200px;float:left"
								src="<%=basePath %>img/picnew.png" onclick="picclick(this.id)"
								data-id="1" alt="图片要求：彩色，清晰，2M以内">
					</div>
					
					<div class="form-group">
						<input type="button" class="btn btn-danger btn-block met1 width-35"
							style="margin-left:30%"	onclick="Addapp()" value="添加">
					</div>
					
				</form>

			</div>
		</div>
	</div>

</div>

<a href="#" id="btn-scroll-up"
	class="btn-scroll-up btn btn-sm btn-inverse"> <i
	class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>

<%@ include file="pub/bottom.jsp"%>
<!-- 引入组件库 -->
<script src="<%=basePath%>DataTables/datatables.min.js"></script>
<script src="<%=basePath%>js/hyl.page.js"></script>
<!-- 自定义脚本 加载区 -->
<script>
	
	var flag=0;
	//添加用户
	function Addapp(){
		var aname = $('#aname').val();
		var ualias = $('#ualias').val();
		var uphone = $('#uphone').val();
		var pic = getCar(_table_);
		
		flag=1;
		$.ajax({
			type : 'get',
			url : '<%=basePath%>admin/Dao/app_new.jsp',
			data : {"aname":aname,"ualias":ualias,"uphone":uphone,"pic":JSON.stringify(pic)},
			success : function(data) {
				var code = data.replace(/\s+/g,"");
				if(code=="error"){
					alert("请确认负责人是否正确");
					flag=0;
					return;
				}else{
					alert("注册成功!");
					window.location.reload();
				}
			}
		});
	}
	
	$('.bt-back').click(function() {
		history.go(-1);
	});

	//只允许输入数字
	$(".onlynum").keyup(function() {
		var c = $(this);
		if (/[^\d]/.test(c.val())) {//替换非数字字符  
			var temp_amount = c.val().replace(/[^\d]/g, '');
			$(this).val(temp_amount);
		}
	})
	
	function getStorage(key){
			 var storage=window.sessionStorage;
			 if (storage.getItem(key))
				 return JSON.parse(storage.getItem(key));
			 else
				 return null;
		} 
		function setStorage(key,value){
			 var storage=window.sessionStorage;
			 storage.setItem(key,JSON.stringify(value));
		}

		var _table_='<%=JSPTITLE%>';
		function getCar(key){
			var li=getStorage(key);
			if (li==undefined ||li==null){
				li=[];
			}
			return li;
		}

		var picname;
		var pubid;   //avatar1
		function picclick(sss){
			var id = $('#'+sss).data("id");
			pubid="uploadFileInput"+id;
			$('#'+pubid).click();
			picname=sss;
		}
		$(".uploadFileInput").change(function() {
			ajaxFileUpload(picname);
		});

		function addsl(ids,paths){
			var obj2 = {id:ids,path:paths};
			var li = [];
			li.push(obj2);
			setStorage(_table_,li);
		}

		//添加c2c时上传图片
		function ajaxFileUpload(picname){
		   $("#loading")  
		    .ajaxStart(function(){  
		        $(this).show();  
		    })//开始上传文件时显示一个图片  
		    .ajaxComplete(function(){  
		        $(this).hide();  
		    });//文件上传完成将图片隐藏起来   
		    var crowd_file = $('#'+pubid)[0].files[0];
		    var formData = new FormData();
		    formData.append("crowd_file",crowd_file);
		    $.ajax({
		 	   //url:'http://www.srv.com/upload?c=1234&s=ygyg&g1=pic&t=3',
		 		//url:'http://localhost:8080/fs/upload?c=1234&s=ygyg&g1=pic&t=3',
		 		url:"http://49.73.43.189:8080/filesrv/upload?c=1234&s=yly&g1=pic&t=3",
		        dataType:'json',
		        type:'POST',
		        async: false,
		        data: formData,
		        processData : false, // 使数据不做处理
		        contentType : false, // 不要设置Content-Type请求头
		        success: function(data){ 
		        	
		      var data=JSON.parse(data.MSG);
		            if (data[0]) {
		            	$('#'+picname).attr('src',data[0].path)
		            	addsl(picname,data[0].path);
		            }
		        },
		        error:function(response){
		            console.log(response);
		        }
		    });
		}
</script>